﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Firestarter.Test.Base;
using FireStarterModeller.Logic;
using Habanero.Base;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.Test.BO.Loaders;
using NUnit.Framework;

namespace FireStarterModeller.Test.Logic.Loaders
{
    [TestFixture]
    public class TestDMXmlBusinessObjectLookupListLoader : TestXmlBusinessObjectLookupListLoader
    {
        [SetUp]
        public override void SetupTest()
        {
            //Runs every time that any testmethod is executed
            //base.SetupTest(); 
            TestUtilsDomain.SetupTest();
            BORegistry.DataAccessor = new DataAccessorInMemory();

            base.Initialise();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
            TestUtilsDomain.SetupFixture();
        }

        [TearDown]
        public void TearDownTest()
        {
            //runs every time any testmethod is complete
        }

        protected override IDefClassFactory GetDefClassFactory()
        {
            return new FMDefClassFactory(TestUtilsShared.CreateUnsavedValidDMSolution());
        }

        [Test]
        public override void TestBusinessObjectLookupListWithSort()
        {
            //---------------Set up test pack-------------------
            const string xml =
                @"<businessObjectLookupList class=""MyBO"" assembly=""Habanero.Test"" sort=""TestProp asc"" />";
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ILookupList lookupList = _loader.LoadLookupList(xml);
            //---------------Test Result -----------------------
            IBusinessObjectLookupList source = (IBusinessObjectLookupList) lookupList;
            Assert.AreEqual("TestProp", source.SortString, "The ASC is not appended due to the fact that it is a default");
        }

        [Test]
        public void TestBusinessObjectLookupListWithSortDesc()
        {
            //---------------Set up test pack-------------------
            //                    MyBO.LoadDefaultClassDef();
            const string xml =
                @"<businessObjectLookupList class=""MyBO"" assembly=""Habanero.Test"" sort=""TestProp desc"" />";
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ILookupList lookupList = _loader.LoadLookupList(xml);
            //---------------Test Result -----------------------
            IBusinessObjectLookupList source = (IBusinessObjectLookupList)lookupList;
            Assert.AreEqual("TestProp DESC", source.SortString);
        }
    }
}